var changePaw = {};
changePaw.methods = {}; 

$(function(){
    // 验证身份表单校验
    changePaw.methods.identityFormCheck();

    // 获取验证码时间
    changePaw.methods.codeBtn();

    // 验证身份表单提交
    changePaw.methods.identityFormSubmit();

    // 修改密码表单校验
    changePaw.methods.pawFormCheck();

    // 修改密码表单提交
    changePaw.methods.pawFormSubmit();
})



// 验证身份表单校验
changePaw.methods.identityFormCheck = function(){
    //验证规则
    $(".shop-identity-form").validate({

        rules:{
            phoneNumber:{
                required:true,
                isMobile : true
            },
            codeNumber:{
                required:true,
                minlength:4,
                maxlength:4
            }
        },
        messages:{
            phoneNumber:{
                required:"请输入手机号",
                isMobile:"请正确填写手机号码" 
            },
            codeNumber:{
                required:"请输入短信验证码",
                minlength:"验证码为四位",
                maxlength:"验证码为四位"
            }
        }
    });

    jQuery.validator.addMethod("isMobile", function(value, element) {  
        var length = value.length;  
        var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;  
        return this.optional(element) || (length == 11 && mobile.test(value)); 
    }, "请正确填写手机号码"); 
}
// 获取验证码时间
changePaw.methods.codeBtn = function(){
    var flag = true;
    $(".shop-identity-form .shop-code-btn").on("click", function () {
        // 启动定时器
        var alltime = 60 * 1000;
        if(flag){
            $(this).html("60s");
            flag = false;
            var timer = setInterval(function () {
                alltime = alltime - 1000;
                var str = parseInt(alltime / 1000) + "s";
                $(".shop-code-btn").html(str.toString());
                if (alltime <= 0) {
                    clearInterval(timer);
                    $(".shop-code-btn").html("获取验证码");
                    flag = true;
                }
            }, 1000)
        }
        
    });
}
// 验证身份表单提交
changePaw.methods.identityFormSubmit = function(){
    $(".shop-identity-form").validate({
        submitHandler:function(form){
            $(form).ajaxSubmit();
        }
    })  

    $(".shop-identity-form .shop-identity-btn").on("click",function(){
        if($('.shop-identity-form').valid()){
            $(".shop-account-paw-form").hide();
            $(".shop-password-form").show();
            $(".shop-account-paw-title .shop-password").addClass("shop-sel");
        }
    })
    
}


// 修改密码表单校验
changePaw.methods.pawFormCheck = function(){
     //验证规则
     $(".shop-password-form").validate({
        rules:{
            password:{
                required:true,
                minlength: 6
            },
            repeatPassword: {
                required: true,
                minlength: 6,
                equalTo: "#password"
            }
        },
        messages:{
            password:{
                required:"请输入用户密码",
                minlength:"用户密码最小六位"
            },
            repeatPassword:{
                required: "请确认用户密码",
                minlength:"用户密码最小六位",
                equalTo: "两次密码不一致"
            }
        }
    });
}
// 修改密码表单提交
changePaw.methods.pawFormSubmit = function(){
    $(".shop-password-form").validate({
        submitHandler:function(form){
            $(form).ajaxSubmit();
        }
    })

    $(".shop-password-form .shop-password-btn").on("click",function(){
        if($('.shop-password-form').valid()){
            $(".shop-account-paw-form").hide();
            $(".shop-account-complete").show();
            $(".shop-account-paw-title .shop-complete").addClass("shop-sel");
        }
        
    })

}




